package com.jinhua.huaojcodesandbox.model.enums;


import org.springframework.util.ObjectUtils;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

public enum QuestionSubmitStateEnum {
    WAITING("带判题",0),
    COMPILING("判题中",1),
    ACCOMPLISH("判题完成",2),
    FAIL("判题失败",3);


    private final String text;

    private final int value;


    QuestionSubmitStateEnum(String text, int value) {
        this.value = value;
        this.text = text;
    }

    /**
     * 获取值列表
     *
     * @return
     */
    public static List<String> getValues() {
        return Arrays.stream(values()).map(item -> item.text).collect(Collectors.toList());
    }

    /**
     * 根据 value 获取枚举
     *
     * @param value
     * @return
     */
    public static QuestionSubmitStateEnum getEnumByValue(Integer value) {
        if (ObjectUtils.isEmpty(value)) {
            return null;
        }
        for (QuestionSubmitStateEnum anEnum : QuestionSubmitStateEnum.values()) {
            if (anEnum.value == value) {
                return anEnum;
            }
        }
        return null;
    }



    public Integer getValue() {
        return value;
    }

    public String getText() {
        return text;
    }
}


